package com.sky.controller.admin;

import com.sky.dto.DishDTO;
import com.sky.dto.DishPageQueryDTO;
import com.sky.entity.Category;
import com.sky.entity.Dish;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.DishService;
import com.sky.vo.DishVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cache.Cache;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@Slf4j
@RequestMapping("/admin/dish")
@RestController
@Api(tags = "菜品相关接口")
public class DishController {
    @Resource
    private DishService dishService;                //菜品
    @Resource
    private RedisTemplate redisTemplate;

    /**
     * 添加菜品
     * @param dishDTO
     * @return
     */
    @PostMapping()
    @ApiOperation("添加菜品")
    public Result insertDish(@RequestBody DishDTO dishDTO){
        dishService.insertDish(dishDTO);

        return Result.success();
    }

    /**
     * 菜品分页查询
     * @param dishPageQueryDTO
     * @return
     */
    @GetMapping("/page")
    @ApiOperation("菜品分页查询")
    public Result<PageResult> selectDish(DishPageQueryDTO dishPageQueryDTO){
        PageResult pageResult = dishService.selectDish(dishPageQueryDTO);
        return Result.success(pageResult);
    }

    /**
     * 删除
     * @param ids
     * @return
     */
    @DeleteMapping
    @ApiOperation("删除菜品")
    public Result deleteDish(@RequestParam List<Long> ids){
        dishService.deleteDish(ids);
        return Result.success();
    }

    /**
     * 根据Id查询菜品信息
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    @ApiOperation("ID查询菜品")
    public Result<DishVO> selectDishById(@PathVariable Long id){
        DishVO dishVO = dishService.selectDishById(id);
        return Result.success(dishVO);
    }
    @GetMapping("/list")
    public Result<List<Dish>> selectCategory(Long categoryId){
        List<Dish> categories = dishService.selectCategory(categoryId);
        return Result.success(categories);
    }
    /**
     * 修改菜品
     * @param dish
     * @return
     */
    @PutMapping
    public Result updateDish(@RequestBody DishVO dish){
        dishService.updateDish(dish);
        return Result.success();
    }

    @PostMapping("/status/{status}")
    public Result updateStatus(@PathVariable Integer status,Long id){
        dishService.updateStatus(status,id);
        return Result.success();
    }
}
